<?php
/**
 * @todo  Order控制器
 * @since 2015-10-16
 */
namespace Api\Controller;
use Think\Controller;
class OrderController extends Controller {
    
    private $key = 'hrb.jjhh.com';
    
    /**
     * @todo    拉去订单数据（对外接口）
     */
    public function apiOrderList(){

        $start_time = (int)I('post.start_time');
        $end_time = (int)I('post.end_time');
        
        $obj = D('Api/Order');
        $list = $obj->apiOrderList($start_time, $end_time);
        if($list === false){
            $return['status'] = '0';
            $return['info'] = $obj->getError();
            //接口访问记录
            \Think\Log::write('获取订单失败.client IP:'.get_client_ip().'===start_time:'.$start_time.'====end_time:'.$end_time.'===错误提示:'.$obj->getError());
        }else{
            $return['status'] = '1';
            $return['info'] = $list;
            //接口访问记录
            \Think\Log::write('获取订单成功.client IP:'.get_client_ip().'===start_time:'.$start_time.'====end_time:'.$end_time.'===获取订单:'.count($list));
        }
        exit($this->callBackEncrypt($return));
    }
    
    public function callBackEncrypt($data){
        $crypt = new \Think\Crypt\Driver\Xxtea();
        return $crypt->encrypt(json_encode($data), $this->key);
    }
    
    public function callBackdecrypt($data){
        $crypt = new \Think\Crypt\Driver\Xxtea();
        return json_decode($crypt->decrypt($data, $this->key), true);
    }
    

    /* public function test(){
     //1444924800 2015-10-16
     //1445011200 2015-10-17
     //1445097600 2015-10-18
     //$start_time = 1443628800;
     //$end_time = 1443628900;
     $curlPost = array(
     'start_time' => '1445011200',
     'end_time' => '1445097600',
     );
     //订单写入接口测试
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL,'http://api.web.local/order/apiOrderList');
     curl_setopt($ch, CURLOPT_HEADER, 0);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
     $data = curl_exec($ch);
     curl_close($ch);
     $decode = $this->callBackdecrypt($data);
     dump($decode);
     //dump($data);//于是结果中就有
     //$array = json_decode($data, true);
     //dump($array['info']['list']);
     } */
    
}